# Maintainer: Andrei Zavada <andrei.zavada@tiot.jp>
pkgname=riak-cs
pkgver=3.0.1
_pkgtag=3.0.1
pkgrel=0
pkgdesc="Riak CS is Riak-backed S3 drop-in replacement"
url="https://github.com/TI-Tokyo/riak_cs"
arch="all !riscv64" # erlang22
license="Apache-2.0"
depends="bash"
makedepends="erlang22 erlang22-dev erlang22-dialyzer"
subpackages="$pkgname-openrc"
source="
	riak_cs-$_pkgtag.tar.gz::https://github.com/TI-Tokyo/riak_cs/archive/refs/tags/$_pkgtag.tar.gz
	riak-cs.initd
	"
builddir="$srcdir/riak_cs-$_pkgtag"

build() {
	git config --global url."https://".insteadOf git://
	make rel-alpine
}

check() {
	make test
}
package() {
	reldir="$PWD/rel/riak-cs"
	mkdir -p "$pkgdir/usr/bin"
	mkdir -p "$pkgdir/usr/sbin"
	mkdir -p "$pkgdir/usr/lib/riak-cs"
	mkdir -p "$pkgdir/var/lib/riak-cs"
	mkdir -p "$pkgdir/var/log/riak-cs"
	mkdir -p "$pkgdir/etc/riak-cs"
	mkdir -p "$pkgdir/run/riak-cs"
	for f in riak-cs-admin riak-cs-supercluster riak-cs-debug; do
	    cp "$reldir/bin/$f" "$pkgdir/usr/bin"
	done
	cp "$reldir/usr/bin/riak-cs" "$pkgdir/usr/sbin"
	install "$reldir/etc/riak-cs.conf" "$pkgdir/etc/riak-cs/riak-cs.conf"
	cp -R "$reldir"/bin        "$pkgdir/usr/lib/riak-cs"
	cp -R "$reldir"/etc/*      "$pkgdir/etc/riak-cs"
	cp -R "$reldir"/erts-*     "$pkgdir/usr/lib/riak-cs"
	cp -R "$reldir"/share      "$pkgdir/usr/lib/riak-cs"
	cp -R "$reldir"/releases   "$pkgdir/usr/lib/riak-cs"
	cp -R "$reldir"/lib        "$pkgdir/usr/lib/riak-cs"

	cp "$reldir/../../misc/prepare-riak-for-cs" "$pkgdir/usr/lib/riak-cs/bin"

	install -m755 -D "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
}

sha512sums="
b0380955f29e134c2cdf550edc44e59e1ab6584ce8fd5e9eed3aeb9e7e923ac5ea8f9f805b72d2d671ba454fb41ea4a5c100653dd4b0adf7e27cc5a9824f6041  riak_cs-3.0.1.tar.gz
3f6f096e00963e1b57d86ae7f67eac766ba137d9c0183c0372869f6e821fbbecfc6c533d07386a74424a9b5f372943eeec89ae217c94d789185493e952d5a6aa  riak-cs.initd
"
